package com.vcredit.creditcat.web;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.tempuri.*;

import com.vcredit.creditcat.framework.annotation.Log;

import javax.annotation.PostConstruct;
import java.net.MalformedURLException;
import java.net.URL;

@Controller
public class SendSmsController {

	@Value("${send.msg.url}")
	private String SEND_MSG_URL;
	private SendMessageServiceSoap msgSoap = null;

	public SendSmsController() {
	}

	@PostConstruct
	public void init() {
		if (this.msgSoap == null) {
			SendMessageService msgService = null;

			try {
				msgService = new SendMessageService(new URL(this.SEND_MSG_URL));
			} catch (MalformedURLException var3) {
				var3.printStackTrace();
			}

			this.msgSoap = msgService.getSendMessageServiceSoap();
		}

	}

	@RequestMapping({"/mobile/sendSms"})
	@ResponseBody
	@Log
	public Boolean sendSmsMessage(@RequestBody SmsMessageData in) throws Exception {
		return this.msgSoap.sendSmsMessage(in);
	}

	@RequestMapping("/mobile/senglist")
	@ResponseBody
	@Log
	public Boolean senglist(@RequestBody ArrayOfSmsMessageData in) throws Exception {
		return this.msgSoap.sendListSmsMessage(in);
	}
}
